﻿using System;
using System.Configuration;

namespace FBGraph.Configuration
{
    /// <summary>Contains configuration elements specific to the FBGraph API.</summary>
    public class FBGraphApiSection : ConfigurationSection
    {
        /// <summary>Contains configuration elements specific to the FBGraph API.</summary>
        public static FBGraphApiSection Api
        {
            get
            {
                var apiSection = ConfigurationManager.GetSection("fbgraph/api");
                if (apiSection != null) return (FBGraphApiSection)apiSection;
                else
                {
                    var empty = new FBGraphApiSection();
                    empty.InitializeDefault();
                    return empty;
                }
            }
        }

        /// <summary>Gets or sets a collection of <see cref="FBGraphApplicationElement" /> elements that define the FBGraph application information to be used by the application.</summary>
        [ConfigurationProperty("applications", IsDefaultCollection = true)]
        [ConfigurationCollection(typeof(FBGraphApplicationElement))]
        public FBGraphApplicationElementCollection Applications
        {
            get { return (FBGraphApplicationElementCollection)this["applications"]; }
            set { this["applications"] = value; }
        }

        /// <summary>Gets or sets the number of times a request will be retried if it fails because of a timeout.</summary>
        /// <remarks>The default value is <c>3</c>.</remarks>
        [ConfigurationProperty("retryCount", DefaultValue = 3, IsRequired = false)]
        public Int32 RetryCount
        {
            get { return (Int32)this["retryCount"]; }
            set { this["retryCount"] = value; }
        }

        /// <summary>Gets or sets the timeout, in milliseconds, that is used for making requests to the Graph API.</summary>
        /// <remarks>The default value is 2500, or 2.5 seconds.</remarks>
        [ConfigurationProperty("requestTimeout", DefaultValue = 2500, IsRequired = false)]
        public Int32 RequestTimeout
        {
            get { return (Int32)this["requestTimeout"]; }
            set { this["requestTimeout"] = value; }
        }
    }
}